package com.pn.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pn.entity.InStore;
import com.pn.entity.Purchase;
import com.pn.mapper.InstoreMapper;
import com.pn.service.InstoreService;
import com.pn.utils.PageBean;
import com.pn.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class InstoreServiceImpl implements InstoreService {
    @Autowired
    private InstoreMapper instoreMapper;

    //显示入库列表
    @Override
    public PageBean instorePageList(InStore inStore) {
        PageHelper.startPage(inStore.getPageNum(),inStore.getPageSize());
        Page<InStore> page = instoreMapper.instorePageList(inStore);
        return new PageBean(page.getTotal(),page.getResult());
    }

    //确认入库
    @Transactional
    @Override
    public Result inStoreConfirm(InStore inStore) {
        int i = instoreMapper.setIsInByid(inStore.getInsId());
        if (i > 0 ){
            int j = instoreMapper.setInventById(inStore.getProductId(),inStore.getInNum());
            if (j > 0){
                return Result.ok("入库单确认成功");
            }
            return Result.err(Result.CODE_ERR_BUSINESS,"入库单确认失败！");
        }
        return Result.err(Result.CODE_ERR_BUSINESS,"入库单确认失败！");

    }
}
